var myGrid;
$(function(){
	myGrid = $("#list").jqGrid({
			url : "webapplication/web-application!datalist",
			datatype : "json",
			mtype : 'GET',
			colNames : [ 
			   '名称',
			   'SSL',
			   '域名',
			   '端口',
			   '路径',
			   '管理'
			],
			colModel : [
			      {
					name : 'name',
					index : 'name',
					width : 80,
					formatter:nameFormatter
				  },
			      {
					name : 'secure',
					index : 'secure',
					width : 30,
					formatter:checkFormatter
				  },
			      {
						name : 'domain',
						index : 'domain',
						width : 100			
				  },
				  {
					  name : 'port',
					  index :'port',
					  width : 20			
				  },
				  {
					  name : 'context',
					  index :'context',
					  width : 50			
				  },
				  {
					  name:'id',
					  index:'id',
					  width:30,
					  formatter:imgFormatter
				  }
			],
			pager : '#pager',
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			sortname : 'name',
			sortorder : 'asc',
			viewrecords : true,
			caption : "应用域列表",
			width : '650',
			height : '300',
			jsonReader : {
				repeatitems : false,
				id : "0"
			}
		});	
	
	
	myGrid.jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	});
	myGrid.jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			doGet("webapplication/web-application-input");
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加",
		id : "newGroup"
	});
});
function nameFormatter(v,opt,row){
	var sid  = row['id'];
	var link = $("<a href='javascript:openEdit(\""+sid+"\");'>"+v+"</a>");
	return $("<p></p>").append(link).html();
}
function openEdit(id){
	var url = "webapplication/web-application!get";
	var data = "bean.id="+id;
	doGet(url,data);
}
function checkFormatter(v,opt,row){
	var chk = $("<input type=checkbox disabled=true />");
	chk.attr("checked",v?true:false);
	return chk.get(0).outerHTML;
}
function imgFormatter(v,opt,row){
	var sid  = row['id'];
	var link = $("<a href='javascript:removeMe(\""+sid+"\");'>删除</a>");
	return $("<p></p>").append(link).html();
}
function removeMe(id){
	$.post("webapplication/web-application!remove","bean.id="+id,function(){
		myGrid.trigger("reload");
	});
}